import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { postCarList } from '@/api/car'

export const useCarStore = defineStore('car', () => {
  // const storage = localStorage.getItem('car')
  // const carContent = storage ? ref(JSON.parse(storage)) : ref()
  const carContent = ref()

  const carTotal = ref<number>()

  async function renewCarContent(token: string, passList?: Carlist[]) {
    //调用接口仓库存购物车数据
    const car = await postCarList({
      token,
      passList
    })
    carContent.value = car.carList

    //存本地
    // localStorage.setItem('car', JSON.stringify(carContent.value))
  }

  return { carContent, renewCarContent ,carTotal}
})
